import request from '@/utils/request.js'

/**
 * 获取所有未读消息
 */
export const getAllUnread = () => request(`/message/count/notRead/all`, 'GET')

/**
 * 获取对话内容
 * @param {Number} chatterId 对话用户的id
 * @param {Date} timestamp 分页的时间，会获取该时间更早的数据
 * @param {Number} cnt 返回几条
 */
export const getChat = ({ chatterId, ...params }) => request(`/im/load/msg/${ chatterId }`, 'GET', params)

/**
 * 轮询获取对话内容
 * @param {Number} chatterId 对话用户的id
 */
export const refreshChat = (chatterId) => request(`/im/refresh/msg/${ chatterId }`, 'POST')

/**
 * 轮询获取消息列表
 */
export const refreshMsgList = () => request(`/im/refresh/comm`, 'POST')

/**
 * 获取消息列表
 * @param {Number} pageNum
 * @param {Number} pageSize
 */
export const getMsgList = (params) => request(`/im/load/comm`, 'GET', params)

/**
 * 发送消息
 * @param {String} context 内容
 * @param {String} type 消息类型，默认common
 * @param {Number} receiverId 接受人
 */
export const sendMsg = (data) => request(`/im/send/msg`, 'POST', data)

/**
 * 撤回消息
 * @param {Number} msgId 消息id
 */
export const withdrawMsg = (msgId) => request(`/im/withdraw/${ msgId }`, 'POST')

/**
 * 获取消息通知列表
 * @param {Number}  pageNum
 * @param {Number}  pageSize
 * @param {String}  type system-系统，private-私信
 */
export const getMessages = (param) => request('/message/status', 'GET', param)

/**
  * 获取消息通知内容
  * @param {Number}  messageId
  */
export const getMessage = (messageId) => request(`/message/${ messageId }`, 'GET')
